class Segments2 extends eui.UILayer {

    protected createChildren(): void {
        super.createChildren();

        egret.lifecycle.addLifecycleListener((context) => {
            // custom lifecycle plugin
        })

        egret.lifecycle.onPause = () => {
            egret.ticker.pause();
        }

        egret.lifecycle.onResume = () => {
            egret.ticker.resume();
        }

        //inject the custom material parser
        //注入自定义的素材解析器
        egret.registerImplementation("eui.IAssetAdapter", new AssetAdapter());
        egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());


        this.runGame().catch(e => {
            console.log(e);
        })
    }

    private async runGame() {
        await this.loadResource()
        this.createGameScene();
    }

    private async loadResource() {
        try {
            await RES.loadConfig("resource/default.res.json", "resource/");
            await this.loadTheme();
        }
        catch (e) {
            console.error(e);
        }
    }

    private loadTheme() {
        return new Promise((resolve, reject) => {
            // load skin theme configuration file, you can manually modify the file. And replace the default skin.
            //加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。
            let theme = new eui.Theme("resource/default.thm.json", this.stage);
            theme.addEventListener(eui.UIEvent.COMPLETE, () => {
                resolve();
            }, this);

        })
    }

    protected createGameScene(): void {
        let segment0:Segment = new Segment(100, 20)
        this.addChild(segment0)
        segment0.x = 100
        segment0.y = 50

        let segment1:Segment = new Segment(200, 10)
        this.addChild(segment1)
        segment1.x = 100
        segment1.y = 80

        let segment2:Segment = new Segment(80, 40)
        this.addChild(segment2)
        segment2.x = 100
        segment2.y = 120

        let vSlider: eui.VSlider = new eui.VSlider();
        vSlider.height = 100;
        vSlider.x = 0;
        vSlider.y = 20;
        vSlider.minimum = 0;//定义最小值
        vSlider.maximum = 100;//定义最大值
        vSlider.value = 0;//定义默认值
        vSlider.touchEnabled = true
        vSlider.addEventListener(eui.UIEvent.CHANGE, this.changeHandler, this);
        this.addChild(vSlider);
    }

    private changeHandler(evt: eui.UIEvent): void {
        console.log(evt.target.value);
    }
   
}